/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.system.xml;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 *
 * @author TOSHIBA
 */
public class XmlNode {
    //ATTRIBUTES
    public static final int TEXT_NODE = 0;
    public static final int ELEMENT_NODE = 1;
    public static final int MAX_HIGH_SCORE = 10;

    private int nodeType = 0;
    private String nodeName = null;
    private String nodeValue = null;
    private Vector children = null;
    private Hashtable attributes = null;

    //CONTRUCTOR
    public XmlNode(int nodeType){
        this.nodeType = nodeType;
        this.children = new Vector();
        this.attributes = new Hashtable();
    }

    /**
     * 
     * @return names
     */
    public String[] getAttributeNames(){
        String[] names = new String[getAttributes().size()];

        Enumeration e = getAttributes().keys();

        int i = 0;

        while(e.hasMoreElements()) {
            names[i] = (String)e.nextElement();
            i++;
        }

        return names;
    }

    public void setAttribute(String key, String value) {
        getAttributes().put(key, value);
    }

    public String getAttribute(String key) {
        return (String)getAttributes().get(key);
    }

    public void addChild(XmlNode child) {
        this.getChildren().addElement(child);
    }

    /*public void dumpXML(XmlNode node, int deep){
        for(int i=0; i < deep; i++) {
            System.out.print(" ");
        }
        if(node.nodeName != null)
            System.out.print(node.nodeName + " - ");

        if(node.nodeValue != null) {
            System.out.print("(" + node.nodeValue + ") - ");
        }
        String[] attributes = node.getAttributeNames();

        for(int i = 0; i < attributes.length; i++) {
            System.out.print(attributes[i] + ": " + node.getAttribute(attributes[i]));
        }
        for(int i=0; i < node.children.size(); i++) {
            dumpXML((XmlNode)node.children.elementAt(i), deep+1);
        }
    }*/

    /**
     * @return the nodeType
     */
    public int getNodeType() {
        return nodeType;
    }

    /**
     * @param nodeType the nodeType to set
     */
    public void setNodeType(int nodeType) {
        this.nodeType = nodeType;
    }

    /**
     * @return the nodeName
     */
    public String getNodeName() {
        return nodeName;
    }

    /**
     * @param nodeName the nodeName to set
     */
    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    /**
     * @return the nodeValue
     */
    public String getNodeValue() {
        return nodeValue;
    }

    /**
     * @param nodeValue the nodeValue to set
     */
    public void setNodeValue(String nodeValue) {
        this.nodeValue = nodeValue;
    }

    /**
     * @return the children
     */
    public Vector getChildren() {
        return children;
    }

    /**
     * @param children the children to set
     */
    public void setChildren(Vector children) {
        this.children = children;
    }

    /**
     * @return the attributes
     */
    public Hashtable getAttributes() {
        return attributes;
    }

    /**
     * @param attributes the attributes to set
     */
    public void setAttributes(Hashtable attributes) {
        this.attributes = attributes;
    }
}
